//
//  DJOANETWORKViewController.m
//  DJOANetWork
//
//  Created by 379903023@qq.com on 06/01/2020.
//  Copyright (c) 2020 379903023@qq.com. All rights reserved.
//

#import "DJOANETWORKViewController.h"
//#import <DJOANetWork/DJOANetWorkManager.h>
#import <DJOANetWork/DJOANetWorkRequest.h>

@interface DJOANETWORKViewController ()

@end

@implementation DJOANETWORKViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    
//    [self getMenuTest];
//    [self loginTest];
    [self uploadImageTest];

}

-(void)getMenuTest{
    DJOANetWorkRequest *request = [[DJOANetWorkRequest alloc] init];
    request.requestMethod = DJOANetWorkRequestMethodPOST;
    request.reqeustTimeoutInterval = 0;
    request.baseUrl = @"http://oatest.cpsol.net/DJOA/message/app_getWorkMsgNum.do";


    request.param = @{@"version":@"ios_1.11.0"};
    request.header = @{@"Cookie":@"token=3a98c56764f24d228da6659421d1e021"};

    [request startWithCompletionBlockWithSuccess:^(__kindof DJOANetWorkRequest * _Nonnull request) {
        NSLog(@"%@",request.responseObject);
    } failure:^(__kindof DJOANetWorkRequest * _Nonnull request) {
        NSLog(@"%@",request.responseObject);
    }];
}

-(void)loginTest{
    DJOANetWorkRequest *request = [[DJOANetWorkRequest alloc] init];
    request.requestMethod = DJOANetWorkRequestMethodPOST;
    request.reqeustTimeoutInterval = 0;
    request.baseUrl = @"http://oatest.cpsol.net/DJOA/newlogin.do";
    request.header = @{
        
    };
    
    request.param = @{
        @"name"      : @"1000190",
        @"password"  : @"339b522501ca880a03acbd86943b1129",
        @"version"   : @"ios_1.11.0"
    };
    [request startWithCompletionBlockWithSuccess:^(__kindof DJOANetWorkRequest * _Nonnull request) {
        NSLog(@"%@",request.responseObject);
        NSArray *cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies;
        NSDictionary *cookiesDict = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
        NSString *cookieStr = [cookiesDict objectForKey:@"Cookie"];
        NSLog(@"%@",cookieStr);
    } failure:^(__kindof DJOANetWorkRequest * _Nonnull request) {
        NSLog(@"%@",request.responseObject);
    }];

}


-(void)uploadImageTest{
    
    DJOANetWorkRequest *request = [[DJOANetWorkRequest alloc] init];
    request.requestMethod = DJOANetWorkRequestMethodPOST;
    request.reqeustTimeoutInterval = 0;
    request.baseUrl = @"http://oatest.cpsol.net/DJOA/app_uploadFileCommon.do";
    request.header = @{
        @"Cookie":@"token=99fcda186f4a4266804a6918c9dbbfb6"
    };
    request.param = @{
        @"version"   : @"ios_1.11.0"
    };
    
    UIImage *image = [UIImage imageNamed:@"testImage"];
    NSData *data = UIImageJPEGRepresentation(image,1.0);

    request.constructingBodyBlock = ^(id<AFMultipartFormData>  _Nonnull formData) {
        [formData appendPartWithFileData:data name:@"file" fileName:@"IMG_0005.JPG" mimeType:@"image/gif"];
    };
    
    [request startWithCompletionBlockWithSuccess:^(__kindof DJOANetWorkRequest * _Nonnull request) {
        NSLog(@"%@",request.responseObject);
    } failure:^(__kindof DJOANetWorkRequest * _Nonnull request) {
        NSLog(@"%@",request.responseObject);
    }];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
